package org.mark.sell.controller;

import org.mark.common.response.Result;
import org.mark.sell.entity.SiteInfo;
import org.mark.sell.service.SiteInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 站点信息
 */
@RestController
@RequestMapping("/siteInfo")
@CrossOrigin
public class SiteInfoController {

    @Autowired
    SiteInfoService siteInfoService;

    @RequestMapping("/selectSiteInfoList")
    public Result selectSiteInfoList( @RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize,
                                      @RequestParam(required = false) String name){
        Result page = siteInfoService.page(pageNum, pageSize, name);
        return page;
    }

    @RequestMapping("/selectSiteInfoById")
    public Result selectSiteInfoById(Integer id) {
        return Result.success(siteInfoService.selectSiteInfoById(id));
    }

    @RequestMapping("/insertSiteInfo")
    public Result insertSiteInfo(@RequestBody SiteInfo siteInfo) {
        if(siteInfoService.insertSiteInfo(siteInfo) > 0){
            return Result.success("操作成功");
        }else {
            return Result.fail("操作失败");
        }
    }

    @RequestMapping("/updateSiteInfoById")
    public Result updateSiteInfoById(@RequestBody SiteInfo siteInfo) {
        if(siteInfoService.updateSiteInfoById(siteInfo) > 0){
            return Result.success("操作成功");
        }else {
            return Result.fail("操作失败");
        }
    }

    @RequestMapping("/deleteSiteInfoById")
    public Result deleteSiteInfoById(@RequestBody SiteInfo siteInfo) {
        return Result.success(siteInfoService.deleteSiteInfoById(siteInfo.getId()));
    }



}
